﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BSCMFF.Core.DataAccessLayer;
using BSCMFF.Core.EmailProvider;
using BSCMFF.Core;

namespace BSCMFF.Web.Pages
{
    public partial class EmployeeInfoOld : MultiLanguagePage
    {
        protected User selectedUser;
        private BSCEntities context;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["EmployeeID"] == null)
            {
                Response.Redirect("EmployeeInfoOld.aspx?EmployeeID=5");
            }
            int employeeID = Convert.ToInt32(Request.QueryString["EmployeeID"]);
           // LabelName.Text = s;

            //if (!IsPostBack)
            //{
                context = new BSCEntities();
                selectedUser = (from user in context.Users
                     //where user.Login == User.Identity.Name
                     where user.ID == employeeID
                     select user).Single();

                //EmployeeName.Text = selectedUser.Login;// u.Firstname + u.Lastname;
                if (selectedUser.Photo != null)
                {
                    RadBinaryImage1.DataValue = selectedUser.Photo;
                }
                else
                {
                    RadBinaryImage1.ImageUrl = "~/Images/silhouette/silhouette-stewie.jpg";
                }
           // }
                //Page.DataBind();
                EmployeeName.DataBind();
                
        }

        protected void RadButtonUploadImage_Click(object sender, EventArgs e)
        {
            if (RadUpload1.UploadedFiles.Count == 1)
            {

                
                long length = RadUpload1.UploadedFiles[0].InputStream.Length;
                //u.Photo = new byte[length];
                byte[] buff = new byte[length];
                RadUpload1.UploadedFiles[0].InputStream.Read(buff, 0, (int)length);
                //RadUploadImage.UploadedFiles[0].

                selectedUser.Photo = buff;

                context.SaveChanges();
                RadBinaryImage1.DataValue = selectedUser.Photo;
            }
        }

        
    }
}